/**
 * 
 */
package cx3k.GUI;

import javax.swing.*;

import cx3k.scheduler.objects.Course;
import cx3k.scheduler.objects.ScheduledSemester;

import java.awt.*;

/**
 * @author Chris
 *
 */
public class SemesterPane extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel semester;
	private Box classBox;
	private ClassDisplay[] classDisplays;
	private JLabel credits;
	private ScheduledCourseGroup courseGroups[];
	private ClassInfo classInfo;
	private CompletedClasses completedClasses;
	
	public SemesterPane(ScheduledSemester semester, ClassInfo classInfo, CompletedClasses cc, SwapPane swap, JLabel scheduleCredits) {
		this.setBackground(MainWindow.MAINCOLOR);
		GridBagLayout gbl = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		this.setLayout(gbl);
		this.classInfo = classInfo;
		this.completedClasses = cc;
		
		this.courseGroups = semester.getCourseGroups();
		this.semester = new JLabel(semester.getTerm());
		this.classBox = Box.createVerticalBox();
		this.classDisplays = new ClassDisplay[courseGroups.length];
		
		int credits = 0;
		
		for (int i = 0; i<courseGroups.length; i++) {
			
			classDisplays[i] = new ClassDisplay(courseGroups[i], classInfo, this.completedClasses, swap);
			classBox.add(classDisplays[i]);
			Course temp[] = courseGroups[i].getCourses();
			if (temp.length == 1) {
				if(temp[0].getCredits().equalsIgnoreCase("TBA"));
				else if(temp[0].getCredits().contains("-"))
					credits += 3;
				else
					credits += new Integer(temp[0].getCredits());
			}
		}
		
		this.credits = new JLabel(credits + "");
		int cred = Integer.parseInt(scheduleCredits.getText());
		scheduleCredits.setText(credits + cred + "");
		
		gbc.gridx = 0;
		gbc.gridy = 0; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 5; 
		gbc.fill = GridBagConstraints.VERTICAL; 
		gbc.anchor = GridBagConstraints.CENTER; 
		gbl.setConstraints(this.semester, gbc);
		this.add(this.semester); 
		
		gbc.gridx = 0;
		gbc.gridy = 1; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 75; 
		gbc.fill = GridBagConstraints.NONE; 
		gbc.anchor = GridBagConstraints.LINE_START; 
		gbl.setConstraints(this.classBox, gbc);
		this.add(this.classBox);
		
		Box hbox = Box.createHorizontalBox();
		hbox.add(new JLabel("Total Credits:  "));
		hbox.add(this.credits);
		
		gbc.gridx = 0;
		gbc.gridy = 2; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 20; 
		gbc.fill = GridBagConstraints.VERTICAL; 
		gbc.anchor = GridBagConstraints.CENTER; 
		gbl.setConstraints(hbox, gbc);
		this.add(hbox);
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
